<?php

use yii\db\Migration;

class m000000_000024_create_sms extends Migration
{
    public function up()
    {
        $this->createTable('{{%sms}}', [
            'id'=>$this->primaryKey(), // PK
            'uid'=>$this->integer(), // 用户编号
            'type'=>$this->integer(), // 短信类型
            'msgid'=>$this->string(32), // 流水号（对应状态）
            'mobile'=>$this->string(32), // 手机号码
            'content'=>$this->text(), // 短信内容
            'send_time'=>$this->integer(), // 发送时间
            'status'=>$this->integer(), // 状态
            'remark'=>$this->text(), // 备注
        ]);
        $this->createIndex('fk_sms_user1_idx', '{{%sms}}', ['uid']);
        try {
            $this->addForeignKey('fk_sms_user1', '{{%sms}}', ['uid'], '{{%user}}', ['id']);
        } catch (Exception $e) {
        }
        $this->batchInsert('{{%key_map}}', ['t', 'k', 'v'], [
            ['sms_type', 1, '注册验证码'],
            ['sms_type', 2, '修改密码'],
            ['sms_type', 3, '身份验证'],
        ]);
        $this->batchInsert('{{%key_map}}', ['t', 'k', 'v'], [
            ['sms_status', 1, '待发送'],
            ['sms_status', 2, '暂停发送'],
            ['sms_status', 3, '提交成功'],
            ['sms_status', 4, '提交失败'],
            ['sms_status', 5, '发送成功'],
            ['sms_status', 6, '发送失败'],
        ]);
    }

    public function down()
    {
        $this->delete('{{%key_map}}', ['t'=>'sms_status']);
        $this->delete('{{%key_map}}', ['t'=>'sms_type']);
        $this->dropTable('{{%sms}}');
    }
}
